<?php
function smarty_modifier_star($star, $type = null) {
	$starhtml = array();
	for ($i = 1; $i <= 5; $i++) {
		if ($star > $i - 0.5) {
			$light = '<i class="iconfont on">&#xe603;</i>';
		} elseif ($star > $i - 1) {
			$light = '<i class="iconfont half"><i class="iconfont half_left">&#xe603;</i>&#xe603;</i>';
		} else {
			$light = '<i class="iconfont off">&#xe603;</i>';
		}

		$starhtml[] = sprintf('<span class="kannb-star">%s</span>', $light);
	}

	switch ($type) {
		case 'QUALITY':
			$saTitle = array('', '糟糕', '较差', '还不错', '值得一试', '强烈推荐');
			$title = $saTitle[floor($star)];
			break;
		case 'STAR':
			$saTitle = array('暂无星级', '', '一星餐厅', '准二星餐厅', '二星餐厅', '准三星餐厅', '三星餐厅', '准四星餐厅', '四星餐厅', '准五星餐厅', '五星餐厅');
			$title = $saTitle[floor($star * 2)];
			break;
		case 'MOVIE':
			$title = sprintf('%.1f', $star * 2);
			break;
		default:
			$title = sprintf('%.1f', $star);
	}

	return sprintf('<span class="kannb-stars" title="%s" style="display:inline-block;">%s</span>', $title, implode('', $starhtml));
}
